*&---------------------------------------------------------------------*
*& Report ZEX_LISTING_112                                              *
*&---------------------------------------------------------------------*
*& Created By: James Wood (james.wood@bowdarkconsulting.com)           *
*& Created On: 12/12/2008                                              *
*& Purpose:    This program shows how to query a person entity using   *
*&             the ABAP Query Service.                                 *
*&---------------------------------------------------------------------*
REPORT zex_listing_112.

*----------------------------------------------------------------------*
* START-OF-SELECTION Event Module                                      *
*----------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM query_person.

*&---------------------------------------------------------------------*
*&      Form  query_person
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM query_person.

* Local Data Declarations:
  DATA: lr_agent      TYPE REF TO zca_os_person,
        lt_people     TYPE osreftab,
        lr_oref       TYPE REF TO object,
        lr_person     TYPE REF TO zcl_os_person,
        lr_query_mgr  TYPE REF TO if_os_query_manager,
        lr_query      TYPE REF TO if_os_query,
        lv_first_name TYPE string,
        lv_last_name  TYPE string.

  TRY.
*   Create a new query based on the first name attribute of
*   the "Person" persistent object:
    lr_agent = zca_os_person=>agent.
    lr_query_mgr = cl_os_system=>get_query_manager( ).
    lr_query = lr_query_mgr->create_query(
      i_filter = 'NAME_FIRST = PAR1' ).

*   Retrieve the set of "Person" objects matching the filter
*   condition:
    lt_people =
      lr_agent->if_os_ca_persistency~get_persistent_by_query(
        i_query = lr_query
        i_par1 = 'Andersen' ).

*   Display the results:
    LOOP AT lt_people INTO lr_oref.
      lr_person ?= lr_oref.
      lv_first_name = lr_person->get_name_first( ).
      lv_last_name = lr_person->get_name_last( ).
      WRITE: / 'Name is: ', lv_first_name, lv_last_name.
    ENDLOOP.
  CATCH cx_os_object_not_found.

  CATCH cx_os_query_error.

  ENDTRY.

ENDFORM.                    "query_person